package infoManage.service;

import infoManage.dao.TeacherDao;
import infoManage.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();
    public boolean addTeacher(Teacher teacher) { // 添加老师
        return teacherDao.addTeacher(teacher);
    }

    public boolean isExists(String id) { // 判断老师id是否存在
        Teacher[] teachers =  teacherDao.findAllTeacher();
        boolean exists = false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher tec = teachers[i];
            if(tec != null && tec.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public Teacher[] findAllTeacher() { // 获取老师信息
        Teacher[] teachers = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher tec = teachers[i];
            if(tec != null) {
                flag = true;
                break;
            }
        }
        if(flag) {
            return teachers;
        } else {
            return null;
        }
    }

    public void deleteTeacher(String id) { // 删除老师信息
        teacherDao.deleteTeacher(id);
    }

    public void editTeacher(Teacher tec) {
        teacherDao.editTeacher(tec);
    }
}
